package com.ycp.erp.goods.ui.activity;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.configure.PickerOptions;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.WheelOptions;
import com.jakewharton.rxbinding2.view.RxView;
import com.one.common.common.stateview.item.EmptyItem;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.model.bean.BannerBean;
import com.one.common.view.base.IListView;
import com.one.common.view.pagestate.listpage.BaseListActivity;
import com.one.common.view.widget.MyTitleBar;
import com.ycp.erp.R;
import com.ycp.erp.brand.presenter.BrandMangerPresenter;
import com.ycp.erp.brand.ui.binder.BrandMangerBinder;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;


/**
 * Class Des:商品管理
 * Created by bjh on 2021/8/24.
 */
@Route(path = RouterPath.GOODS_MANAGER)
public class GoodsManagerActivity extends BaseListActivity<BrandMangerPresenter> implements IListView {
    private ArrayList<String> arrayList=new ArrayList<>();
    private ArrayList<String> arrayListGoods=new ArrayList<>();
    @Override
    protected void initPresenter() {
        mPresenter = new BrandMangerPresenter(this, getContext());
    }

    @Override
    public void registerDate() {
        BrandMangerBinder brandMangerBinder = new BrandMangerBinder();
        register(BannerBean.class, brandMangerBinder);
    }

    @Override
    public void loadData() {
        mPresenter.getBrands();
    }

    @SuppressLint("CheckResult")
    @Override
    public void initView() {
        super.initView();
        addTopView(R.layout.layout_search_goods);
        addBottomView(R.layout.layout_submit_bottom);
        TextView tvSubmit = successView.findViewById(R.id.tvSubmit);
        tvSubmit.setText("添加商品");
        RelativeLayout rlFilterwarehouse = successView.findViewById(R.id.rlFilterwarehouse);
        TextView tvFilterwarehouse = successView.findViewById(R.id.tvFilterwarehouse);
        ImageView ivFilterWarehouseTriangle = successView.findViewById(R.id.ivFilterWarehouseTriangle);
        RelativeLayout rlFilterGoods = successView.findViewById(R.id.rlFilterGoods);
        TextView tvFilterGoods = successView.findViewById(R.id.tvFilterGoods);
        ImageView ivFilterGoodsTriangle = successView.findViewById(R.id.ivFilterGoodsTriangle);
        arrayList.add("全部库房");
        arrayList.add("库房库房1");
        arrayList.add("库房库房2");
        arrayList.add("库房库房2");
        arrayList.add("库房库房2");
        arrayList.add("全部库房");
        arrayListGoods.add("全部商品");
        arrayListGoods.add("根据商品名排序");
        arrayListGoods.add("只看有库存商品");
        arrayListGoods.add("只看预警商品");
        arrayListGoods.add("只看有正常商品");
        //跳转
        RxView.clicks(tvSubmit).throttleFirst(2, TimeUnit.SECONDS).subscribe(o -> {
            RouterManager.getInstance().go(RouterPath.ADD_GOODS);
        });
        RxView.clicks(rlFilterwarehouse).throttleFirst(100, TimeUnit.MILLISECONDS).subscribe(o -> {
            //筛选dialog
            OptionsPickerView<String> build = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    tvFilterwarehouse.setText("当前库房："+arrayList.get(options1));
                }
            }).setSubmitColor(getResources().getColor(R.color.root_blue))
                    .setCancelColor(getResources().getColor(R.color.gray_d6))
                    .setLineSpacingMultiplier(2.8f)
                    .build();
            build.setPicker(arrayList);
            build.show();
//            if (ivFilterWarehouseTriangle.isSelected()) {
//                ivFilterWarehouseTriangle.setImageResource(R.mipmap.triangle_up);
//
//            } else {
//                ivFilterWarehouseTriangle.setImageResource(R.mipmap.triangle_down);
//            }
//            ivFilterWarehouseTriangle.setSelected(!ivFilterWarehouseTriangle.isSelected());
        });
        RxView.clicks(rlFilterGoods).throttleFirst(100, TimeUnit.MILLISECONDS).subscribe(o -> {
//            if (ivFilterGoodsTriangle.isSelected()) {
//                ivFilterGoodsTriangle.setImageResource(R.mipmap.triangle_up);
//            } else {
//                ivFilterGoodsTriangle.setImageResource(R.mipmap.triangle_down);
//            }
//            ivFilterGoodsTriangle.setSelected(!ivFilterGoodsTriangle.isSelected());
            //筛选dialog
            OptionsPickerView<String> build = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    tvFilterGoods.setText("筛选："+arrayList.get(options1));
                }
            }).setSubmitColor(getResources().getColor(R.color.root_blue))
                    .setCancelColor(getResources().getColor(R.color.gray_d6))
                    .setLineSpacingMultiplier(2.8f)
                    .build();
            build.setPicker(arrayListGoods);
            build.show();
        });
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                .setTitleText("商品管理").hideLine();
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter.getBrands();
    }

    @Override
    public boolean onEmpty() {
        addData(new EmptyItem("暂无数据"));
        return true;
    }


    @Override
    public void onErrorClick() {
        super.onErrorClick();
        refresh();
    }
}
